<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>module AddressSource - RDoc Documentation</title>

<link href="./fonts.css" rel="stylesheet">
<link href="./rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
</script>

<script src="./js/jquery.js"></script>
<script src="./js/navigation.js"></script>
<script src="./js/search_index.js"></script>
<script src="./js/search.js"></script>
<script src="./js/searcher.js"></script>
<script src="./js/darkfish.js"></script>


<body id="top" role="document" class="module">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="./index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    
    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-i-lookup">#lookup</a>
    
    <li ><a href="#method-i-title">#title</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="module-AddressSource">
  <h1 id="module-AddressSource" class="module">
    module AddressSource
  </h1>

  <section class="description">
    
<p>Test module for rspec providing functions to lookup contacts in the
test-contacts directory</p>

  </section>

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="REGEX">REGEX
        
        <dd><p><a href="AddressSource.html#REGEX">REGEX</a> to extract contact data from
the contact source file</p>
        
      
        <dt id="URL">URL
        
        <dd><p><a href="AddressSource.html#URL">URL</a> where the contact source files can
be found</p>
        
      
      </dl>
    </section>
    

    

    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-lookup" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">lookup</span><span
            class="method-args">(pattern = {})</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Looks up a contact based on the pattern</p>
          
          

          
          <div class="method-source-code" id="lookup-source">
            <pre><span class="ruby-comment"># File spec/sycontact/files/address_source.rb, line 25</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">lookup</span>(<span class="ruby-identifier">pattern</span> = {})
  <span class="ruby-identifier">contacts</span> = []
  <span class="ruby-identifier">create_source_files</span>(<span class="ruby-identifier">pattern</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">source_file</span><span class="ruby-operator">|</span>

    <span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span> <span class="ruby-identifier">source_file</span>

    <span class="ruby-identifier">source</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">source_file</span>)

    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">empty?</span>

    <span class="ruby-identifier">values</span> = {}

    <span class="ruby-constant">REGEX</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">regex</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">value</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-identifier">regex</span>)[<span class="ruby-value">0</span>]
      <span class="ruby-identifier">values</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">contacts</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">values</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">contacts</span>.<span class="ruby-identifier">keep_if</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">contact</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">each</span>.<span class="ruby-identifier">reduce</span>(<span class="ruby-keyword">true</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">match</span>, <span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span> 
      <span class="ruby-identifier">contact_does_not_have_key</span> = <span class="ruby-identifier">contact</span>[<span class="ruby-identifier">pattern</span>[<span class="ruby-value">0</span>]].<span class="ruby-identifier">nil?</span>
      <span class="ruby-identifier">regex</span> = <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">pattern</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">downcase</span>)
      <span class="ruby-identifier">pos</span> = <span class="ruby-identifier">regex</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">contact</span>[<span class="ruby-identifier">pattern</span>[<span class="ruby-value">0</span>]].<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">contact_does_not_have_key</span>
      <span class="ruby-identifier">match</span> <span class="ruby-keyword">and</span> (<span class="ruby-keyword">not</span> <span class="ruby-identifier">pos</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">contact_does_not_have_key</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-title" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">title</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Overrides the default title method in AddressBook</p>
          
          

          
          <div class="method-source-code" id="title-source">
            <pre><span class="ruby-comment"># File spec/sycontact/files/address_source.rb, line 56</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">title</span>
  <span class="ruby-string">&quot;AddressSource&quot;</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>
</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="http://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.1.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>

